﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/HomeSite.Master" Inherits="System.Web.Mvc.ViewPage<TimeTableManagement.Entities.Tb_Role>" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>

<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>

    <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="100%" 
        CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" 
        GroupBoxCaptionOffsetY="-28px" 
        SpriteCssFilePath="~/App_Themes/Aqua/{0}/sprite.css">
        <ContentPaddings Padding="14px" />
        <PanelCollection>
<dx:PanelContent runat="server" SupportsDisabledAttribute="True">
<% using (Html.BeginForm()) { %>
    <%: Html.ValidationSummary(true) %>

        <%: Html.HiddenFor(model => model.id) %>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.rolename) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.rolename) %>
            <%: Html.ValidationMessageFor(model => model.rolename) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.description) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.description) %>
            <%: Html.ValidationMessageFor(model => model.description) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.value) %>
        </div>
        <div class="editor-field">
            <% 
        int id = Model.id;
        TimeTableManagement.Entities.Tb_Role _role = new TimeTableManagement.Entities.Tb_Role();
        List<TimeTableManagement.Entities.Role> list = _role.getRoleModule(id);  
        %>
        <table style="color:#333333;width:100%;border-collapse:collapse;">
            <tr style="color:White;background-color:#507CD1;font-weight:bold;">
                <td class="style5">
                    Module</td>
                <td class="style5">
                    View</td>
                <td class="style5">
                    Create</td>
                <td class="style5">
                    Edit</td>
                <td class="style5">
                    Delete</td>
                <td class="style5">
                    Full</td>
            </tr>
            <% int i =0 ; foreach (TimeTableManagement.Entities.Role r in list)
               { i++; %>
               <% if (i % 2 != 0)
                  { %>
            <tr style="background-color:#EFF3FB;">
            <% }
                  else
                  { %>
                  <tr style="background-color:White;">
            <% } %>
                <td class="style2">
                    <%= r.t %></td>
                    <td class="style5">
                        <% if (new TimeTableManagement.Entities.Tb_Role().getPermission(r.r, "view").Equals("x"))
                           { %>
                            <input id="Checkbox<%= (i*10+1) %>" type="checkbox" checked=checked/>
                        <% }
                           else
                           { %>
                            <input id="Checkbox<%= (i*10+1) %>" type="checkbox"/>
                        <% } %>
                        </td>
                    <td class="style5">
                        <% if (new TimeTableManagement.Entities.Tb_Role().getPermission(r.r, "create").Equals("x"))
                           { %>
                            <input id="Checkbox<%= (i*10+2) %>" type="checkbox" checked=checked/>
                        <% }
                           else
                           { %>
                            <input id="Checkbox<%= (i*10+2) %>" type="checkbox"/>
                        <% } %>
                        </td>
                    <td class="style5">
                        <% if (new TimeTableManagement.Entities.Tb_Role().getPermission(r.r, "edit").Equals("x"))
                           { %>
                            <input id="Checkbox<%= (i*10+3) %>" type="checkbox" checked=checked/>
                        <% }
                           else
                           { %>
                            <input id="Checkbox<%= (i*10+3) %>" type="checkbox"/>
                        <% } %>
                        </td>
                    <td class="style5">
                        <% if (new TimeTableManagement.Entities.Tb_Role().getPermission(r.r, "delete").Equals("x"))
                           { %>
                            <input id="Checkbox<%= (i*10+4) %>" type="checkbox" checked=checked/>
                        <% }
                           else
                           { %>
                            <input id="Checkbox<%= (i*10+4) %>" type="checkbox"/>
                        <% } %>
                        </td>
                    <td class="style5">
                        <input id="Checkbox<%= (i*10+5) %>" type="checkbox" onclick ="selectAll(this)" /></td>
                        <script type="text/javascript">
                            function selectAll(pointer) {
                                $group = pointer.id.substr(0, 9);
                                $value = pointer.checked;
                                for (i = 1; i <= 4; i++) {
                                    $item = $group + i.toString();
                                    //alert($item);
                                    document.getElementById($item).checked = $value;

                                }
                            }
                        </script>
                    </td>
            </tr>
            <% } %>
        </table>    
        </div>
        <div class="editor-field"><%: Html.HiddenFor(model => model.value) %>
        
        <p>
            <input type="submit" value="Save" onclick="return updatejson()" />
        </p>
<% } %>

<div>
    <%: Html.ActionLink("Back to List", "Index") %>
</div>
</dx:PanelContent>
</PanelCollection>
    </dx:ASPxRoundPanel>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <%--Can mot Javascript, khi co 1 check vao trong table, thi lap tuc thay doi gia tri cua chuoi tai day--%>
    <script>
        function updatejson() {
            $role = '[{"m":"sys","t":"System","r":' + countingpermission('1') + '},' +
            '{"m":"sch","t":"Information School","r":' + countingpermission('2') + '},' +
            '{"m":"stu","t":"Information Student","r":' + countingpermission('3') + '},' +
            '{"m":"lec","t":"Information Lecture","r":' + countingpermission('4') + '},' +
            '{"m":"cou","t":"Course","r":' + countingpermission('5') + '},' +
            '{"m":"roo","t":"Room","r":' + countingpermission('6') + '},' +
            '{"m":"tim","t":"Time Tablel","r":' + countingpermission('7') + '},' +
            '{"m":"new","t":"New","r":' + countingpermission('8') + '}]';
            document.getElementById('value').value = $role;
            return true;
        }
        function countingpermission($id) {
            $cout = 0;
            if (document.getElementById('Checkbox' + $id + '1').checked) {
                $cout = $cout + 1;
            }
            if (document.getElementById('Checkbox' + $id + '2').checked) {
                $cout = $cout + 2;
            }
            if (document.getElementById('Checkbox' + $id + '3').checked) {
                $cout = $cout + 4;
            }
            if (document.getElementById('Checkbox' + $id + '4').checked) {
                $cout = $cout + 8;
            }
            return $cout;
        }
    </script>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="leftmenu" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="menuright" runat="server">
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="Footer" runat="server">
</asp:Content>
